<template>
  <div class="app-container customer-div">
    <el-menu :default-active="listQuery.tab" class="el-menu-demo" mode="horizontal" @select="handleSelect">
      <el-menu-item index="myCharge">我的</el-menu-item>
      <el-menu-item index="all" v-if="AllInquirySupplierPrice">全部</el-menu-item>
    </el-menu>
    <div style="margin-top: 40px">
      <!--搜索-->
      <el-form :inline="true" :model="listQuery" size="mini" label-width="100px">
        <el-form-item label="报价时间：">
          <el-date-picker
            v-model="listQuery.priceDate"
            type="daterange"
            format="yyyy 年 MM 月 dd 日"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="品类：">
          <el-input v-model="listQuery.goodsName" clearable></el-input>
        </el-form-item>
        <el-form-item label="牌号：">
          <el-input v-model="listQuery.goodsSn" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            @click="handleSearchList()"
            type="primary">
            查询
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <!--数据列表-->
    <div class="table-container">
      <el-table
        v-loading="listLoading"
        :data="tableData"
        border
        style="width: 100%; margin-top: 20px">
        <el-table-column
          align="center"
          label="报价时间"
          min-width="150">
          <template slot-scope="scope">
              {{scope.row.priceDate}}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="报价类型"
          min-width="100">
          <template slot-scope="scope">
            {{scope.row.priceType | fiftype}}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="品类"
          min-width="100">
          <template slot-scope="scope">
              {{scope.row.goodsName}}
          </template>
        </el-table-column>
        <el-table-column
          label="牌号"
          min-width="180"
          align="center">
          <template slot-scope="scope">
            {{scope.row.goodsSn}}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="数量"
          min-width="100">
          <template slot-scope="scope">
            {{scope.row.goodsNum}}
          </template>
        </el-table-column>
        <el-table-column
          label="价格"
          min-width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.supplierPrice}}
          </template>
        </el-table-column>
        <el-table-column
          align="center" label="供应商" min-width="200">
          <template slot-scope="scope">
            {{scope.row.supplierName}}
          </template>
        </el-table-column>
        <el-table-column
          label="联系电话"
          min-width="150"
          align="center">
          <template slot-scope="scope">
            {{scope.row.supplierMobile}}
          </template>
        </el-table-column>

      </el-table>
    </div>
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total, sizes,prev, pager, next,jumper"
        :current-page.sync="listQuery.pageNum"
        :page-size="listQuery.pageSize"
        :page-sizes="[10,15,20]"
        :total="count">
      </el-pagination>
    </div>



  </div>
</template>
<script>
import {getInquirySupplierPriceList} from '@/api/allInLine/inquiry'
import store from '@/store'
import { mapGetters } from 'vuex'
const defaultListQuery={
  "priceDate": [], //报价时间
  "goodsName": "", //品名
  "goodsSn": "", //牌号
  "tab": "myCharge", //all-全部，myCharge-我的
  "pageSize": 10,
  "pageNum": 1
};

export default {
  name: "myInquirySupplierPrice",
  data(){
    return {
      listQuery: JSON.parse(JSON.stringify(defaultListQuery)),
      tableData: [],
      count: 0,
      listLoading: false,
      roles:store.getters.roles ? store.getters.roles : [],
      btnLoading:false,
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'mobile',
      'userId'
    ]),

    AllInquirySupplierPrice(){
      if(this.roles.indexOf("AllInquirySupplierPrice") != -1){
        return true
      }else{
        return false
      }
    }
  },
  created() {
    this.getList();

  },
  filters: {
    fiftype(val){
       if(val === 0){
         return '采购员报价'
       }else if(val === 10){
         return '供应商报价'
       }else{
         return ''
       }
    },
  },

  methods:{
    handleSelect(key){
      this.listQuery = JSON.parse(JSON.stringify(defaultListQuery))
      this.listQuery.tab = key;
      this.handleSearchList();
    },

    handleSizeChange(val){
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val){
      this.listQuery.pageNum = val;
      this.getList();
    },

    handleSearchList(){
      this.listQuery.pageNum = 1;
      this.getList();
    },

    //获取列表
    getList() {
      this.listLoading = true;
      getInquirySupplierPriceList(this.listQuery).then(response => {
        this.tableData = response.list;
        this.count = response.count;
        this.listLoading = false;
      }).catch(()=>{
        this.listLoading = false;
      });
    },

  },
}
</script>


